/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package events.animation;

import gui.SnazzySpritesGUI;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JComboBox;
import renderer.AnimateAndRenderTask;
import renderer.SceneRenderer;
import snazzysprites.SnazzySprites;
import state.SnazzySpritesStateManager;
import static snazzysprites.SnazzySpritesSettings.*;
import state.SnazzySpritesState;

/**
 * Handles the selection of a sprite type's animation
 * @author Andrew Gratta <andrew.gratta@stonybrook.edu>
 */
public class SelectAnimationHandler implements ItemListener
{

    @Override
    public void itemStateChanged(ItemEvent e) {
        if (e.getStateChange() == ItemEvent.SELECTED)
        {
            SnazzySprites singleton = SnazzySprites.getSnazzySprites();
            SnazzySpritesStateManager manager = singleton.getStateManager();
            SnazzySpritesGUI gui = singleton.getGUI();
            JComboBox combo = (JComboBox)e.getSource();
            String animationName = combo.getSelectedItem().toString();
            if (animationName.equals(ANIMATION_COMBOBOX_TEXT))
            {
                return;
            }
            manager.setAnimation(animationName);
            SceneRenderer renderer = gui.getPreviewRenderer();
            renderer.unpauseScene();
        }
    }
    
}
